
package org.dydl.common.config;

import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@ConfigurationProperties(prefix = "static.resources", ignoreUnknownFields = true, exceptionIfInvalid = true)
@Component
public class StaticResourcesConfiguration {
	private String permission;
	private String anonymous;
	private String libs;

	public String getPermission() {
		
		return this.permission;
	}

	public void setPermission(String permission) {
		Path path = Paths.get(permission, new String[0]);
		if (Files.exists(path, new LinkOption[] { LinkOption.NOFOLLOW_LINKS }) && Files.isDirectory(path, new LinkOption[] { LinkOption.NOFOLLOW_LINKS }) && Files.isReadable(path)) {
			this.permission = path.toUri().toString();
		} else {
			throw new IllegalArgumentException("Location " + permission + " for static files is not accessible directory.");
		}
	}

	public String getAnonymous() {
		
		return this.anonymous;
	}

	public void setAnonymous(String anonymous) {
		Path path = Paths.get(anonymous, new String[0]);
		if (Files.exists(path, new LinkOption[] { LinkOption.NOFOLLOW_LINKS }) && Files.isDirectory(path, new LinkOption[] { LinkOption.NOFOLLOW_LINKS }) && Files.isReadable(path)) {
			this.anonymous = path.toUri().toString();
		} else {
			throw new IllegalArgumentException("Location [" + anonymous + "] for anonymous files is not accessible directory.");
		}
	}

	public String getLibs() {
		
		return this.libs;
	}

	public void setLibs(String libs) {
		Path path = Paths.get(libs, new String[0]);
		if (Files.exists(path, new LinkOption[] { LinkOption.NOFOLLOW_LINKS }) && Files.isDirectory(path, new LinkOption[] { LinkOption.NOFOLLOW_LINKS }) && Files.isReadable(path)) {
			this.libs = path.toUri().toString();
		} else {
			throw new IllegalArgumentException("Location [" + libs + "] for libs files is not accessible directory.");
		}
	}
}